package com.yanyeori.webtest.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.net.URL;

/**
 * @author chenkuan
 * @since 2022/7/26 026 10:48
 */
@Slf4j
@Service
public class WebTestService {

    /**
     * 读取resources下的静态文件
     */
    public static void test1() {
        URL url = WebTestService.class.getClassLoader().getResource("application.yml");
        if (url != null) {
            String path = url.getPath();
            log.info(path);
        }

        ClassPathResource resource = new ClassPathResource("application.yml");
        if (resource.exists()) {
            try {
                File file = resource.getFile();
                log.info("path:{}", file.getPath());
                log.info("parent:{}", file.getParent());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
